const Koa = require('koa');
const app = new Koa();
const staticServer = require('koa-static');
const views = require('koa-views')
const path = require('path')
const Router = require('koa-router');
const router = new Router();
const bodyParse=require("koa-bodyparser")
const createTemplate=require("../create_template")
app.use(staticServer(__dirname ,"./static"));

// 加载模板引擎
app.use(views(path.join(__dirname, './static/views'), {
    extension: 'html'
}))

app.use(bodyParse())


router.post('/createTemplate', async (ctx, next) => {
    let ddl=ctx.request.body.ddl
    ctx.response.body =createTemplate(ddl)
    next();
});

/*app.use(async ctx => {
    await ctx.render('index', {

    })
});*/

app.use(router.routes());


app.listen(13000);